* Rainer Kotschy and Uwe Sunde
* Income Shocks, Inequality, and Democracy
* Replication File



clear all
set more off
cd
use "ks_data_sje.dta"
xtset id t

// install packages before proceeding
*ssc install estout // package for extracting estimates
*findit grc1leg // package to combine graphs with a common legend


// Table 1a

qui xtreg piv_score L.piv_score L.(c.lrgdppc##c.gini) L.yos td1960-td2014, fe r
eststo est_1

qui xtreg fh_score L.fh_score L.(c.lrgdppc##c.gini) L.yos td1960-td2014, fe r
eststo est_2

qui xtreg dd_score L.dd_score L.(c.lrgdppc##c.gini) L.yos td1960-td2014, fe r
eststo est_3

qui xtreg pc_score L.pc_score L.(c.lrgdppc##c.gini) L.yos td1960-td2014, fe r
eststo est_4

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(td* L.yos _cons) order(L.piv_score L.fh_score L.dd_score L.pc_score) scalars(N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Table 1b

qui xtreg piv_score L.piv_score L.nshock L.gini L.nshock_gini L.lrgdppc L.yos td1960-td2014, fe r
eststo est_1
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_1
ma drop M

qui xtreg fh_score L.fh_score L.nshock L.gini L.nshock_gini L.lrgdppc L.yos td1960-td2014, fe r
eststo est_2
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_2
ma drop M

qui xtreg dd_score L.dd_score L.nshock L.gini L.nshock_gini L.lrgdppc L.yos td1960-td2014, fe r
eststo est_3
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_3
ma drop M

qui xtreg pc_score L.pc_score L.nshock L.gini L.nshock_gini L.lrgdppc L.yos td1960-td2014, fe r
eststo est_4
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_4
ma drop M

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(td* L.lrgdppc L.yos _cons) order(L.piv_score L.fh_score L.dd_score L.pc_score) scalars(N_shock N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Table 2

qui xtreg demo_piv L3.piv_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r	
eststo est_1
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_1
qui ta demo_piv if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_1
ma drop M Q

qui xtreg demo_fh L3.fh_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r	
eststo est_2
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_2
qui ta demo_fh if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_2
ma drop M Q

qui xtreg demo_dd L3.dd_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r	
eststo est_3
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_3
qui ta demo_dd if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_3
ma drop M Q

qui xtreg demo_pc L3.pc_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r	
eststo est_4
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_4
qui ta demo_pc if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_4
ma drop M Q

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(L3.lrgdppc L3.yos td* _cons) order(L3.piv_score L3.fh_score L3.dd_score L3.pc_score) scalars(N_demo N_shock N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Figure 2

g l3gini = L3.gini
g gini_sq = L3.gini*L3.gini


// Panel a

qui xtreg demo_piv L3.piv_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r

#delimit;

mat list e(b);
mat b = e(b);
loc e_s = b[1,2];
loc e_int = b[1,4];
		
mat list e(V);
mat v = e(V);
loc v_s = v[2,2];
loc v_int = v[4,4];
loc v_cov = v[4,2];

g te_2a = `e_s' + `e_int'*l3gini if e(sample) == 1;
g se_2a = sqrt(`v_s' + `v_int'*gini_sq + 2*`v_cov'*l3gini) if e(sample) == 1;
g cilb_2a = te_2a - 1.96*se_2a if e(sample) == 1;
g ciub_2a = te_2a + 1.96*se_2a if e(sample) == 1;

twoway
		
hist l3gini if e(sample) == 1,
	color(ltbluishgray)
	ysca(titlegap(2) off) yaxis(1)
	ylabel(, nogrid axis(1))
|| (line te_2a l3gini, sort clcolor(navy)
	title("PolityIV Index", size(small))
	ytitle("Marginal effect on democratization", size(small) axis(2))
	ysca(titlegap(2)) yaxis(2)
	ylabel(-.2(.1).3 -.2 "-0.2" -.1 "-0.1" .1 "0.1" .2 "0.2" .3 "0.3" 
		, angle(0) nogrid labsize(small) axis(2))
	yline(0, lcolor(ltbluishgray) axis(2))
	xtitle("Inequality", size(small))
	xsca(titlegap(2))
	xlabel(.2(.1).7 .2 "0.2" .3 "0.3" .4 "0.4" .5 "0.5"	.6 "0.6" .7 "0.7",
		labsize(small))
	graphregion(color(white)) bgcolor(white)
	legend(order (2 3 1) rows(1) cols(3)
		label(1 "Density of inequality")
		label(2 "Marginal effect")
		label(3 "95% confidence interval") size(vsmall)))
|| (line cilb_2a l3gini, sort clcolor(navy) lpattern(dash) yaxis(2))
|| (line ciub_2a l3gini, sort clcolor(navy) lpattern(dash) yaxis(2)),
	saving("fig2a.gph", replace)
;

#delimit cr


// Panel b

qui xtreg demo_fh L3.fh_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
	
#delimit;

mat list e(b);
mat b = e(b);
loc e_s = b[1,2];
loc e_int = b[1,4];

mat list e(V);
mat v = e(V);
loc v_s = v[2,2];
loc v_int = v[4,4];
loc v_cov = v[4,2];

g te_2b = `e_s' + `e_int'*l3gini if e(sample) == 1;
g se_2b = sqrt(`v_s' + `v_int'*gini_sq + 2*`v_cov'*l3gini) if e(sample) == 1;
g cilb_2b = te_2b - 1.96*se_2b if e(sample) == 1;
g ciub_2b = te_2b + 1.96*se_2b if e(sample) == 1;

twoway
	
hist l3gini if e(sample) == 1,
	color(ltbluishgray)
	ysca(titlegap(2) off) yaxis(1)
	ylabel(, nogrid axis(1))
|| (line te_2b l3gini, sort clcolor(navy)
	title("Political Rights and Civil Liberties", size(small))
	ytitle("Marginal effect on democratization", size(small) axis(2))
	ysca(titlegap(2)) yaxis(2)
	ylabel(-.2(.1).3 -.2 "-0.2" -.1 "-0.1" .1 "0.1" .2 "0.2" .3 "0.3" 
		, angle(0) nogrid labsize(small) axis(2))
	yline(0, lcolor(ltbluishgray) axis(2))
	xtitle("Inequality", size(small))
	xsca(titlegap(2))
	xlabel(.2(.1).7 .2 "0.2" .3 "0.3" .4 "0.4" .5 "0.5" .6 "0.6" .7 "0.7",
		labsize(small))
	graphregion(color(white)) bgcolor(white)
	legend(off))
|| (line cilb_2b l3gini, sort clcolor(navy) lpattern(dash) yaxis(2))
|| (line ciub_2b l3gini, sort clcolor(navy) lpattern(dash) yaxis(2)),
	saving("fig2b.gph", replace)
;

#delimit cr


// Panel c

qui xtreg demo_dd L3.dd_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r

#delimit;
	
mat list e(b);
mat b = e(b);
loc e_s = b[1,2];
loc e_int = b[1,4];

mat list e(V);
mat v = e(V);
loc v_s = v[2,2];
loc v_int = v[4,4];
loc v_cov = v[4,2];

g te_2c = `e_s' + `e_int'*l3gini if e(sample) == 1;
g se_2c = sqrt(`v_s' + `v_int'*gini_sq + 2*`v_cov'*l3gini) if e(sample) == 1;
g cilb_2c = te_2c - 1.96*se_2c if e(sample) == 1;
g ciub_2c = te_2c + 1.96*se_2c if e(sample) == 1;

twoway
	
hist l3gini if e(sample) == 1,
	color(ltbluishgray)
	ysca(titlegap(2) off) yaxis(1)
	ylabel(, nogrid axis(1))
|| (line te_2c l3gini, sort clcolor(navy)
	title("Democracy-Dictatorship Index", size(small))
	ytitle("Marginal effect on democratization", size(small) axis(2))
	ysca(titlegap(2)) yaxis(2)
	ylabel(-.2(.1).3 -.2 "-0.2" -.1 "-0.1" .1 "0.1" .2 "0.2" .3 "0.3" 
		, angle(0) nogrid labsize(small) axis(2))
	yline(0, lcolor(ltbluishgray) axis(2))
	xtitle("Inequality", size(small))
	xsca(titlegap(2))
	xlabel(.2(.1).7 .2 "0.2" .3 "0.3" .4 "0.4" .5 "0.5" .6 "0.6" .7 "0.7",
		labsize(small))
	graphregion(color(white)) bgcolor(white)
	legend(off))
|| (line cilb_2c l3gini, sort clcolor(navy) lpattern(dash) yaxis(2))
|| (line ciub_2c l3gini, sort clcolor(navy) lpattern(dash) yaxis(2)),
	saving("fig2c.gph", replace)
;

#delimit cr


// Panel d

qui xtreg demo_pc L3.pc_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r

#delimit;
		
mat list e(b);
mat b = e(b);
loc e_s = b[1,2];
loc e_int = b[1,4];

mat list e(V);
mat v = e(V);
loc v_s = v[2,2];
loc v_int = v[4,4];
loc v_cov = v[4,2];

g te_2d = `e_s' + `e_int'*l3gini if e(sample) == 1;
g se_2d = sqrt(`v_s' + `v_int'*gini_sq + 2*`v_cov'*l3gini) if e(sample) == 1;
g cilb_2d = te_2d - 1.96*se_2d if e(sample) == 1;
g ciub_2d = te_2d + 1.96*se_2d if e(sample) == 1;

twoway
		
hist l3gini if e(sample) == 1,
	color(ltbluishgray)
	ysca(titlegap(2) off) yaxis(1)
	ylabel(, nogrid axis(1))
|| (line te_2d l3gini, sort clcolor(navy)
	title("Principal Components", size(small))
	ytitle("Marginal effect on democratization", size(small) axis(2))
	ysca(titlegap(2) alt) yaxis(2)
	ylabel(-.2(.1).3 -.2 "-0.2" -.1 "-0.1" .1 "0.1" .2 "0.2" .3 "0.3" 
		, angle(0) nogrid labsize(small) axis(2))
	yline(0, lcolor(ltbluishgray) axis(2))
	xtitle("Inequality", size(small))
	xsca(titlegap(2))
	xlabel(.2(.1).7 .2 "0.2" .3 "0.3" .4 "0.4" .5 "0.5" .6 "0.6" .7 "0.7",
		labsize(small))
	graphregion(color(white)) bgcolor(white)
	legend(off))
|| (line cilb_2d l3gini, sort clcolor(navy) lpattern(dash) yaxis(2) )
|| (line ciub_2d l3gini, sort clcolor(navy) lpattern(dash) yaxis(2)),
	saving("fig2d.gph", replace)
;

#delimit cr


grc1leg "fig2a.gph" "fig2b.gph" "fig2c.gph" "fig2d.gph", legendfrom("fig2a.gph") span graphregion(color(white)) ycommon xcommon



// Table 3

qui xtreg demo_piv L3.piv_score L3.nshock L3.pshock L3.gini L3.nshock_gini L3.pshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_1
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_1
qui ta pshock if e(sample) == 1, matcell(R)
loc r = R[2,1]
estadd loc N_pshock "`r'": est_1
qui ta demo_piv if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_1
ma drop M Q R

qui xtreg demo_fh L3.fh_score L3.nshock L3.pshock L3.gini L3.nshock_gini L3.pshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_2
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_2
qui ta pshock if e(sample) == 1, matcell(R)
loc r = R[2,1]
estadd loc N_pshock "`r'": est_2
qui ta demo_fh if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_2
ma drop M Q R
		
qui xtreg demo_dd L3.dd_score L3.nshock L3.pshock L3.gini L3.nshock_gini L3.pshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_3
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_3
qui ta pshock if e(sample) == 1, matcell(R)
loc r = R[2,1]
estadd loc N_pshock "`r'": est_3
qui ta demo_dd if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_3
ma drop M Q R		

qui xtreg demo_pc L3.pc_score L3.nshock L3.pshock L3.gini L3.nshock_gini L3.pshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_4
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_4
qui ta pshock if e(sample) == 1, matcell(R)
loc r = R[2,1]
estadd loc N_pshock "`r'": est_4
qui ta demo_pc if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_4
ma drop M Q R	

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(L3.lrgdppc L3.yos td* _cons) order(L3.piv_score L3.fh_score L3.dd_score L3.pc_score) scalars(N_demo N_shock N_pshock N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Table 4

qui xtreg demo_piv L3.piv_score L3.infshock L3.gini L3.infshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_1
qui ta infshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_1
qui ta demo_piv if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_1
ma drop M Q

qui xtreg demo_fh L3.fh_score L3.infshock L3.gini L3.infshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_2
qui ta infshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_2
qui ta demo_fh if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_2
ma drop M Q
		
qui xtreg demo_dd L3.dd_score L3.infshock L3.gini L3.infshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_3
qui ta infshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_3
qui ta demo_dd if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_3
ma drop M Q

qui xtreg demo_pc L3.pc_score L3.infshock L3.gini L3.infshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_4
qui ta infshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_4
qui ta demo_pc if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_4
ma drop M Q	

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(L3.lrgdppc L3.yos td* _cons) order(L3.piv_score L3.fh_score L3.dd_score L3.pc_score) scalars(N_demo N_shock N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Table 5

qui xtreg demo_piv L3.piv_score L3.default L3.gini L3.default_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_1
qui ta default if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_default "`m'": est_1
qui ta demo_piv if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_1
ma drop M Q

qui xtreg demo_fh L3.fh_score L3.default L3.gini L3.default_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_2
qui ta default if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_default "`m'": est_2
qui ta demo_fh if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_2
ma drop M Q	
		
qui xtreg demo_dd L3.dd_score L3.default L3.gini L3.default_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_3
qui ta default if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_default "`m'": est_3
qui ta demo_dd if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_3
ma drop M Q	

qui xtreg demo_pc L3.pc_score L3.default L3.gini L3.default_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_4
qui ta default if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_default "`m'": est_4
qui ta demo_pc if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_4
ma drop M Q	

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(L3.lrgdppc L3.yos td* _cons) order(L3.piv_score L3.fh_score L3.dd_score L3.pc_score) scalars(N_demo N_default N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Table 6

qui xtreg demo_piv L3.piv_score L3.ntrend L3.gini L3.ntrend_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_1
qui ta ntrend if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_trend "`m'": est_1
qui ta demo_piv if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_1
ma drop M Q

qui xtreg demo_fh L3.fh_score L3.ntrend L3.gini L3.ntrend_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_2
qui ta ntrend if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_trend "`m'": est_2
qui ta demo_fh if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_2
ma drop M Q

qui xtreg demo_dd L3.dd_score L3.ntrend L3.gini L3.ntrend_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_3
qui ta ntrend if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_trend "`m'": est_3
qui ta demo_dd if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_3
ma drop M Q

qui xtreg demo_pc L3.pc_score L3.ntrend L3.gini L3.ntrend_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_4
qui ta ntrend if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_trend "`m'": est_4
qui ta demo_pc if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_4
ma drop M Q

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(L3.lrgdppc L3.yos td* _cons) order(L3.piv_score L3.fh_score L3.dd_score L3.pc_score) scalars(N_demo N_trend N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Table 7a

egen mdemo_piv = mean(demo_piv), by(id)
egen mdemo_fh = mean(demo_fh), by(id)
egen mdemo_dd = mean(demo_dd), by(id)
egen mdemo_pc = mean(demo_pc), by(id)

qui xtreg nvdemo_piv L3.piv_score L3.conflict L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014 if mdemo_piv > 0, fe r
eststo est_1
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_1
qui ta nvdemo_piv if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_1
ma drop M Q

qui xtreg nvdemo_fh L3.fh_score L3.conflict L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014 if mdemo_fh > 0, fe r
eststo est_2
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_2
qui ta nvdemo_fh if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_2
ma drop M Q

qui xtreg nvdemo_dd L3.dd_score L3.conflict L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014 if mdemo_dd > 0, fe r
eststo est_3
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_3
qui ta nvdemo_dd if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_3
ma drop M Q

qui xtreg nvdemo_pc L3.pc_score L3.conflict L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014 if mdemo_pc > 0, fe r
eststo est_4
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_4
qui ta nvdemo_pc if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_4
ma drop M Q

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(L3.lrgdppc L3.yos td* _cons) order(L3.piv_score L3.fh_score L3.dd_score L3.pc_score) scalars(N_demo N_shock N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Table 7b

qui xtreg vdemo_piv L3.piv_score L3.conflict L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014 if mdemo_piv > 0, fe r
eststo est_1
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_1
qui ta vdemo_piv if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_1
ma drop M Q
		
qui xtreg vdemo_fh L3.fh_score L3.conflict L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014 if mdemo_fh > 0, fe r
eststo est_2
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_2
qui ta vdemo_fh if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_2
ma drop M Q

qui xtreg vdemo_dd L3.dd_score L3.conflict L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014 if mdemo_dd > 0, fe r
eststo est_3
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_3
qui ta vdemo_dd if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_3
ma drop M Q

qui xtreg vdemo_pc L3.pc_score L3.conflict L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014 if mdemo_pc > 0, fe r
eststo est_4
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_4
qui ta vdemo_pc if e(sample) == 1, matcell(Q)
loc q = Q[2,1]
estadd loc N_demo "`q'": est_4
ma drop M Q

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(L3.lrgdppc L3.yos td* _cons) order(L3.piv_score L3.fh_score L3.dd_score L3.pc_score) scalars(N_demo N_shock N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



// Table 8

qui xtreg riotd L3.piv_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_1
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_1
ma drop M

qui xtreg riotd L3.fh_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_2
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_2
ma drop M

qui xtreg riotd L3.dd_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_3
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_3
ma drop M

qui xtreg riotd L3.pc_score L3.nshock L3.gini L3.nshock_gini L3.lrgdppc L3.yos td1960-td2014, fe r
eststo est_4
qui ta nshock if e(sample) == 1, matcell(M)
loc m = M[2,1]
estadd loc N_shock "`m'": est_4
ma drop M

esttab est_*, b(%3.2f) se(%3.2f) star(* .1 ** .05 *** .01) drop(L3.lrgdppc L3.yos td* _cons) order(L3.piv_score L3.fh_score L3.dd_score L3.pc_score) scalars(N_shock N_g) obslast r2(%3.2f) sfmt(a1) compress
est drop _all



clear all
exit
